package com.knife.blog.logic.impl;

import java.util.List;

import com.knife.blog.domain.FriendLink;
import com.knife.blog.logic.CurrentUser;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class FriendLinkServiceImpl extends DAOSupportService implements
		com.knife.blog.logic.FriendLinkService {

	private static FriendLinkServiceImpl singleton=new FriendLinkServiceImpl();
	public static FriendLinkServiceImpl getInstance()
	{
		return singleton;
	}
	public boolean addFriendLink(FriendLink link) {
		boolean ret = false;
		link.setInputtime(new java.util.Date());
		link.setInputuser(CurrentUser.getActiveUser().getUserName());
		link.setStatus(new Integer(0));
		ret = this.dao.save(link);
		return ret;
	}

	public int batchDelFriendLink(String[] cids) {
		int ret = 0;
		for (int i = 0; i < cids.length; i++) {
			if (delFriendLink(cids[i]))
				ret++;
		}
		return ret;
	}

	public boolean delFriendLink(String cid) {
		boolean ret = false;
		this.dao.del(getFriendLink(cid));
		return ret;
	}

	public FriendLink getFriendLink(String cid) {
		return (FriendLink) this.dao.get(FriendLink.class, cid);
	}

	public List getTopFriendLink(String username, int topNum) {
		String scope = "inputuser=? ";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		paras.add(username);
		DbPageList pList = new DbPageList(FriendLink.class, scope, paras);
		pList.doList(1, topNum);
		return pList.getResult();
	}

	public IPageList queryFriendLink(String username, int currentPage,
			int pageSize) {
		String scope = "inputuser=? ";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		paras.add(username);
		DbPageList pList = new DbPageList(FriendLink.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}

	public boolean updateFriendLink(FriendLink link) {
		boolean ret=false;
		ret=this.dao.update(link);
		return ret;
	}
}